package com.parq.cs.crawl;

import java.sql.ResultSet;
import java.util.Iterator;

import org.apache.log4j.Logger;

import com.parq.cs.db.CSDBProxy;
import com.parq.ie.google.customsearch.CSResult;

public class standAloneImplementation {

	private static Logger log = Logger.getLogger(CSCrawlerController.class);
	
	public static void main(String [] args)throws Exception{
		
		log.info("Starting Stand Alone Implementation");
		CSDBProxy db = new CSDBProxy(); 
		CSDBProxy db2 = new CSDBProxy();
		
		ResultSet rset=db.getCrawlTasks(); 
		
		int i=0;
		while (rset.next()){
			long id=rset.getLong("searchid");
			
			String resultsFeed = rset.getString("searchresults");
			log.info(id);
			CSResult result = new CSResult(resultsFeed,id);
			
			CSCrawlerController controller=new CSCrawlerController(result,id);
			
			Iterator<CSCrawlResult> itr=controller.getResults().iterator();
			while(itr.hasNext()){
				CSCrawlResult res=itr.next();
				if (i<3)
					System.out.println(res.getUrl() + ": "  + res.getSentences());
				++i;
//				db2.addSearchResultContents(id, res.getSentences(), res.getUrl());
			}
		}
		
		db2.close();
		db.close();
		log.info("Stoping Stand Alone Implementation");
	}
}
